﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entitty;

namespace ClassLibrary.DAO
{
    public class TblUserAccountDAO
    {
        private DBService _db = null;
        public TblUserAccountDAO(string ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public TblUserAccount GetLogin(string email, string pass)
        {
            TblUserAccount user = new TblUserAccount();
            try
            {
                DataTable dt =_db.ExeSP_DataTable("sp_TblUserAccount_GetLogin", 
                                new string [] {"@Email", "@Password"},
                                new object[]{email, pass}, CommandType.StoredProcedure);
                foreach (DataRow dr in dt.Rows)
                {
                    user.AccountID = Convert.ToInt32(dr["AccountID"].ToString());
                    user.FirstName = dr["FirstName"].ToString();
                    user.LastName = dr["LastName"].ToString();
                    user.Password = pass;
                    user.Email = email;
                    user.IsAdmin = Boolean.Parse(dr["IsAdmin"].ToString());
                }
	       
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return user;
        }
    }
}
